//在线操作与离线操作
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
int a[N], s[N], last[N]; //last[x]表示x上一次出现的下标
#define lowbit(x) (x & -x)
int n, m;
int ret[N];

struct node
{
    int l, r, id;
}q[N];

void modify(int x, int k)
{
    for(int i = x; i <= n; i += lowbit(i)) s[i] += k;
}

int query(int x)
{
    int sum = 0;
    for(int i = x; i; i -= lowbit(i)) sum += s[i];
    return sum;
}

bool cmp(node& x, node& y)
{
    return x.r < y.r;
}

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    scanf("%d", &m);
    for(int i = 1; i <= m; i++)
    {
        scanf("%d%d", &q[i].l, &q[i].r);
        q[i].id = i;
    }

    sort(q + 1, q + 1 + m, cmp);
    int pos = 1;
    for(int i = 1; i <= m; i++)
    {
        int l = q[i].l, r = q[i].r, id = q[i].id;
        while(pos <= r) 
        {
            if(last[a[pos]]) modify(last[a[pos]], -1);
            modify(pos, 1);
            last[a[pos]] = pos;
            pos++;
        }
        ret[id] = query(r) - query(l - 1);
    }

    for(int i = 1; i <= m; i++) printf("%d\n", ret[i]);
    return 0;
}